package com.example.shop_2304.minefg

import androidx.lifecycle.viewModelScope
import com.example.base.entity.OrderEntity
import com.example.base.entity.Res
import com.example.base.mvvm.BaseViewModel
import com.example.base.param.PRefund
import com.example.base.utils.SingleLiveData
import kotlinx.coroutines.launch

class PayViewModel:BaseViewModel() {
    //请求订单列表
    val success = SingleLiveData<Res<OrderEntity>>()
    val fail = SingleLiveData<String>()
    fun order(type:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                success.postValue(apiService.order(type, limit, page))
            } catch (e: Exception) {
                fail.postValue(e.message.toString())
            }
        }
    }

    val refundSuccess = SingleLiveData<Res<String?>>()
    val refundFail = SingleLiveData<String>()
    fun refund(pRefund: PRefund){
        viewModelScope.launch {
            try {
                refundSuccess.postValue(apiService.refund(pRefund))
            } catch (e: Exception) {
                refundFail.postValue(e.message.toString())
            }
        }
    }
}